package com.example.question.list.list1;

/**
 * @Date 2023-07-05
 * @Author Jonathan
 */
public class Code10_206 {
    public static void main(String[] args) {
        Code10_206 code = new Code10_206();
        ListNode listNode = List.createList(new int[]{1, 2, 3, 4, 5, 6});
        ListNode node = code.reverseList(listNode);
        List.printLink(node);
    }

    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }

        ListNode node = reverseList(head.next);
        head.next.next = head;
        head.next = null;
        return node;
    }

    // todo 试一下迭代的方式
}
